// 目标：提供封装了执行商品列表分类相关功能的异步请求 api方法
// 导入 axios
import axios from "../utils/requset.js"
// 按需导出api方法
// 请求商品列表
export const getGoodsList = (params) => axios({
  url: 'categories',
  method: 'get',
  params
})

// 添加商品
export const addGoods = (data) => axios({
  url: 'categories',
  method: 'post',
  data
})

export const getCateParams = (id, type) => axios({
  url: `categories/${id}/attributes?sel=${type}`
})

export const addCateParams = (id, name, sel) => axios({
  url: `categories/${id}/attributes`, method: 'post', data: { attr_name: name, attr_sel: sel }
})

export const chkEditCateParams = (id, attrId, sel) => axios({
  url: `categories/${id}/attributes/${attrId}`, method: 'get', params: sel
})

export const EditCateParams = (id, attrId, name, sel) => axios({
  url: `categories/${id}/attributes/${attrId}`, method: 'put', data: {
    attr_name: name,
    attr_sel: sel
  }
})

export const delCateParams = (id, attrId) => axios({
  url: `categories/${id}/attributes/${attrId}`, method: 'delete'
})

// 编辑提交参数
export const putCateParams = (cid, aid, attr_name, attr_sel, attr_vals) => axios({
  url: `categories/${cid}/attributes/${aid}`,
  method: 'put',
  data: {
      attr_name,
      attr_sel,
      attr_vals
  }
})